
export default {
    /*
     * 函数节流
     * @param {function} method 要进行节流的函数
     * @param {number} delay 延时时间(ms)
     * @param {number} duration 经过duration时间(ms)必须执行函数method
     */
    throttle: function (method, delay, duration) {
        var timer = null,
            begin = null;
        return function () {
            debugger
            var context = this,
                args = arguments,
                current = new Date();
            if (!begin) {
                begin = current;
            }
            if (timer) {
                window.clearTimeout(timer);
            }
            if (duration && current - begin >= duration) {
                method.apply(context, args);
                begin = null;
            } else {
                timer = window.setTimeout(function () {
                    method.apply(context, args);
                    begin = null;
                }, delay);
            }
        };
    },
};